package com.gavel.utils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class StringUtils {

    public static String trim(String value) {
        if ( value==null ) {
            return "";
        }
        return value.trim();
    }

    public static boolean isBlank(String value) {
        if ( value==null ) {
            return true;
        }
        return value.trim().length()==0;
    }

    public static boolean isNotBlank(String value) {
        if ( value==null ) {
            return false;
        }
        return value.trim().length()>0;
    }


    /**
     * 不区分大小写替换
     * @param source
     * @param target
     * @param replacement
     * @return
     */
    public static String replaceIgnoreCase(String source, String target, String replacement){
        Pattern p = Pattern.compile(target, Pattern.CASE_INSENSITIVE);
        Matcher m = p.matcher(source);
        return m.replaceAll(replacement);
    }
}
